﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LogicWaveWpf.Common
{
    public class UIHelper
    {
        //public static void Invoke(Control ctrl, Action ac)
        //{
        //    if (ctrl.InvokeRequired)
        //        ctrl.Invoke(ac);
        //    else ac();
        //}

        //public static void BeginInvoke(Control ctrl, Action ac)
        //{
        //    if (ctrl.InvokeRequired)
        //        ctrl.BeginInvoke(ac, null);
        //    else ac();
        //}

        public static Color GetColor(int index)
        {
            if (_colors == null) InitColors();
            return Color.FromKnownColor((KnownColor)_colors[index]);
        }

        public static Color GetColorEx(int index) => Color.FromKnownColor(_colorsEx[index % _colorsEx.Length]);

        static int[] _colors;
        static KnownColor[] _colorsEx = new KnownColor[] { KnownColor.Purple, KnownColor.Blue, KnownColor.Green, KnownColor.Yellow, KnownColor.Orange, KnownColor.Red, KnownColor.Gray, KnownColor.DarkRed };
        static void InitColors()
        {
            var colors = new List<int>();
            foreach (var item in Enum.GetValues(typeof(KnownColor)))
                colors.Add((int)item);
            colors.Remove(3); colors.Remove(10); colors.Remove(11); colors.Remove(18); colors.Remove(20); colors.Remove(22); colors.Remove(26); colors.Remove(27); colors.Remove(35);
            _colors = colors.ToArray();
        }


    }
}
